#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

import bs4

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

url = r'https://www.taobao.com'

options = webdriver.ChromeOptions()
if False:
    options.headless = True

headers = {
    'User-Agent': 'user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36',
    'Accept-Language': 'zh-CN,zh;q=0.1'
}

cap = DesiredCapabilities.CHROME.copy()

for key, value in headers.items():
    cap['chorme.page.customHeaders.%s' % key] = value

driver = webdriver.Chrome(options=options, desired_capabilities=cap)

driver.get(url)

wait = WebDriverWait(driver, 10)
wait.until(expected_conditions.element_to_be_clickable((By.CLASS_NAME, 'member')))

button = driver.find_element_by_class_name('btn-login')  # Compound class names not permitted
button.click()

# wait.until(expected_conditions.element_to_be_clickable((By.CLASS_NAME, 'iconfont')))
driver.implicitly_wait(5)


n = driver.window_handles
driver.switch_to.window(n[1]) # switch to new window

# switch = driver.find_element_by_class_name('login-switch')
# switch.click()

username = driver.find_element_by_id('TPL_username_1')
password = driver.find_element_by_id('TPL_password_1')
username.send_keys('songcwzjut')
password.send_keys('zjut2008')

# action = webdriver.ActionChains(driver)
# source = driver.find_element_by_xpath("//*[@id='nc_1_n1t']/span") #需要滑动的元素
# action.click_and_hold(source).perform()
# action.move_by_offset(298, 0) #需要滑动的坐标
# action.release().perform()
# driver.implicitly_wait(2)
# button = driver.find_element_by_name('button')
# wait.until(expected_conditions.element_to_be_clickable((By.CLASS_NAME, 'iconfont')))
# button.click()

butt = driver.find_element_by_id('J_SubmitStatic')
butt.click()
 
driver.get("https://www.taobao.com")
# 设置显示等待
wait = WebDriverWait(driver, 10)
wait.until(expected_conditions.presence_of_element_located((By.CLASS_NAME, 'search-combobox-input-wrap')))
search = driver.find_element_by_class_name('search-combobox-input')
search.send_keys("风衣")


